﻿using Agnes.Core;

namespace Agnes.MyDocsLib
{
    public class ChangeTitleViewModel
        : ScreenBase<Catalog>
    {
        public ChangeTitleViewModel(Catalog model)
        {
            DisplayName = "修改标题";
            Model = model;
            CanSave = Model.IsValid;
            Model.PropertyChanged += (sender, args) =>
                                         {
                                             CanSave = Model.IsValid;
                                         };
        }

        protected override object CreateView()
        {
            return new ChangeTitleView();
        }

        private bool _canSave = false;

        public bool CanSave
        {
            get { return _canSave; }
            set
            {
                _canSave = value;
                NotifyOfPropertyChange(() => CanSave);
            }
        }

        public void Save()
        {
            ArticleManager.Instance.Save();
            this.TryClose(true);
        }

        public void Cancel()
        {
            this.TryClose(false);
        }
    }
}
